package com.hd.hdxgddcommon.entity.dto;

import com.hd.hdxgddcommon.constant.ResultConst;
import lombok.experimental.Accessors;

import java.util.LinkedHashMap;

@Accessors(chain = true)
public class ResultDto extends LinkedHashMap<String, Object> {

    public final static String CODE = "code";
    public final static String MSG = "msg";
    public final static String DATA = "data";

    protected Object data;


    public ResultDto() {
    }

    public ResultDto(Exception e) {
        this(0, e.getMessage());
    }

    public Integer getCode() {
        Object code = this.get("code");
        return code != null ? (Integer) code : null;
    }

    public String getMsg() {
        Object msg = this.get("msg");
        return msg != null ? (String) msg : null;
    }

    public ResultDto(Integer code) {
        this.put("code", code);
    }

    public ResultDto(Integer code, String msg) {
        this.put(CODE, code);
        this.put(MSG, msg);
    }

    public ResultDto(ResultConst resultConst) {
        this(resultConst.getCode(), resultConst.getMsg());
    }

    public ResultDto(ResultConst resultConst, String msg, Object data) {
        this(resultConst.getCode(), msg, data);
    }

    public ResultDto(ResultConst resultConst, Object data) {
        this(resultConst.getCode(), resultConst.getMsg(), data);
    }

    public ResultDto(Integer code, String msg, Object data) {
        this.put(CODE, code);
        this.put(MSG, msg);
        this.put(DATA, data);

    }

    public ResultDto put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public ResultDto msg(String msg) {
        this.put(MSG, msg);
        return this;
    }
}
